home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / lfs / lfsDirOpLog.c < prev    next >
C/C++ Source or Header  |  1990-11-15  |  6KB  |  175 lines

  1. /* 
  2.  * lfsDirOpLog.c --
  3.  *
  4.  *    Routines for LFS directory change log.
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/lfs/RCS/lfsDirOpLog.c,v 1.2 90/11/15 11:05:51 mendel Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <fs.h>
  21. #include <fsdm.h>
  22. #include <lfsInt.h>
  23.  
  24.  
  25. /*
  26.  * FILL_IN_ENTRY - Fill in a new log entry.
  27.  */
  28. #define FILL_IN_ENTRY(entryPtr, opFlags)                 \
  29.     (entryPtr)->hdr.opFlags = opFlags;                    \
  30.     (entryPtr)->hdr.dirFileNumber = dirFileNumber;            \
  31.     (entryPtr)->hdr.dirOffset = dirOffset;                \
  32.     (entryPtr)->hdr.linkCount =                     \
  33.         (fileDescPtr == (Fsdm_FileDescriptor *) NIL) ?    0 :    \
  34.                 fileDescPtr->numLinks;            \
  35.     (entryPtr)->dirEntry.fileNumber = fileNumber;            \
  36.     (entryPtr)->dirEntry.recordLength = Fslcl_DirRecLength(nameLen);    \
  37.     (entryPtr)->dirEntry.nameLength = nameLen;                \
  38.     bcopy(name, (entryPtr)->dirEntry.fileName, nameLen);
  39.  
  40.  
  41. /*
  42.  *----------------------------------------------------------------------
  43.  *
  44.  * Lfs_DirOpStart --
  45.  *
  46.  *    Mark the start of a directory operation on an OFS file system.
  47.  *
  48.  * Results:
  49.  *    NIL
  50.  *    
  51.  *
  52.  * Side effects:
  53.  *    Log record added. Will sleep until checkpoint operation done.
  54.  *
  55.  *----------------------------------------------------------------------
  56.  */
  57.  
  58. ClientData
  59. Lfs_DirOpStart(domainPtr, opFlags, name, nameLen, fileNumber, fileDescPtr,
  60.          dirFileNumber, dirOffset, dirFileDescPtr)
  61.     Fsdm_Domain    *domainPtr;    /* Domain containing the object being modified.
  62.                  */
  63.     int        opFlags;    /* Operation code and flags. See fsdm.h for
  64.                  * definitions. */
  65.     char    *name;        /* Name of object being operated on. */
  66.     int        nameLen;    /* Length in characters of name. */
  67.     int        fileNumber;    /* File number of objecting being operated on.*/
  68.     Fsdm_FileDescriptor *fileDescPtr; /* FileDescriptor object being operated on
  69.                        * before operation starts. */
  70.     int        dirFileNumber;    /* File number of directory containing object.*/
  71.     int        dirOffset;    /* Byte offset into directory of the directory
  72.                  * entry containing operation. */
  73.     Fsdm_FileDescriptor *dirFileDescPtr; /* FileDescriptor of directory before
  74.                       * operation starts. */
  75. {
  76.     Lfs    *lfsPtr = LfsFromDomainPtr(domainPtr);
  77.     LfsDirOpLogEntry *entryPtr;
  78.     ClientData    clientData;
  79.     Boolean found;
  80.     int     entrySize;
  81.  
  82. #define    LOCKPTR    &lfsPtr->lock
  83.     LOCK_MONITOR;
  84.  
  85.     while (lfsPtr->activeFlags & LFS_CHECKPOINT_ACTIVE) {
  86.     Sync_Wait(&lfsPtr->checkPointWait, FALSE);
  87.     }
  88.     lfsPtr->dirModsActive++;
  89.     UNLOCK_MONITOR;
  90. #undef LOCKPTR
  91. #define    LOCKPTR    &lfsPtr->logLock
  92.  
  93.     LOCK_MONITOR;
  94.     entrySize = Fslcl_DirRecLength(nameLen) + sizeof(LfsDirOpLogEntryHdr);
  95.     entryPtr = LfsDirLogEntryAlloc(lfsPtr, entrySize,  -1, &found);
  96.     FILL_IN_ENTRY(entryPtr, opFlags);
  97.     clientData = (ClientData) entryPtr->hdr.logSeqNum;
  98.     UNLOCK_MONITOR;
  99.  
  100.     return clientData;
  101. }
  102.  
  103. /*
  104.  *----------------------------------------------------------------------
  105.  *
  106.  * Lfs_DirOpEnd --
  107.  *
  108.  *    Mark the end of a directory operation on an LFS file system.
  109.  *
  110.  * Results:
  111.  *    None
  112.  *    
  113.  *
  114.  * Side effects:
  115.  *    None.
  116.  *
  117.  *----------------------------------------------------------------------
  118.  */
  119.  
  120. void
  121. Lfs_DirOpEnd(domainPtr, clientData, status, opFlags, name, nameLen, 
  122.         fileNumber,  fileDescPtr, dirFileNumber, dirOffset,
  123.         dirFileDescPtr)
  124.     Fsdm_Domain    *domainPtr;    /* Domain containing the object modified. */
  125.     ClientData    clientData;    /* ClientData as returned by DirOpStart. */
  126.     ReturnStatus status;    /* Return status of the operation, SUCCESS if
  127.                  * operation succeeded. FAILURE otherwise. */
  128.     int        opFlags;    /* Operation code and flags. See fsdm.h for
  129.                  * definitions. */
  130.     char    *name;        /* Name of object being operated on. */
  131.     int        nameLen;    /* Length in characters of name. */
  132.     int        fileNumber;    /* File number of objecting being operated on.*/
  133.     Fsdm_FileDescriptor *fileDescPtr; /* FileDescriptor object after
  134.                       * operation.*/
  135.     int        dirFileNumber;    /* File number of directory containing object.*/
  136.     int        dirOffset;    /* Byte offset into directory of the directory
  137.                  * entry containing operation. */
  138.     Fsdm_FileDescriptor *dirFileDescPtr; /* FileDescriptor of directory after
  139.                       * operation. */
  140. {
  141.     Lfs    *lfsPtr = LfsFromDomainPtr(domainPtr);
  142.     int logSeqNum = (int) clientData;
  143.     LfsDirOpLogEntry *entryPtr;
  144.     int entrySize;
  145.     Boolean found;
  146.  
  147.  
  148. #define    LOCKPTR    &lfsPtr->logLock
  149.     LOCK_MONITOR;
  150.     entrySize = Fslcl_DirRecLength(nameLen) + sizeof(LfsDirOpLogEntryHdr);
  151.     entryPtr = LfsDirLogEntryAlloc(lfsPtr, entrySize, logSeqNum, &found);
  152.     if (!found) { 
  153.     FILL_IN_ENTRY(entryPtr, opFlags);
  154.     } else {
  155.     entryPtr->hdr.opFlags |= opFlags;
  156.     entryPtr->hdr.dirOffset = dirOffset;
  157.     if (fileDescPtr != (Fsdm_FileDescriptor *) NIL) {
  158.         entryPtr->hdr.linkCount = fileDescPtr->numLinks;
  159.     }
  160.     entryPtr->dirEntry.fileNumber = fileNumber;
  161.     }
  162.     UNLOCK_MONITOR;
  163. #undef LOCKPTR
  164. #define    LOCKPTR    &lfsPtr->lock
  165.     LOCK_MONITOR;
  166.     lfsPtr->dirModsActive--;
  167.     if (lfsPtr->dirModsActive == 0) {
  168.     Sync_Broadcast(&lfsPtr->checkPointWait);
  169.     }
  170.     UNLOCK_MONITOR;
  171.  
  172.     return;
  173. }
  174.  
  175.